import Vue from "vue";
import VueRouter from "vue-router";
import routes from './home'

Vue.use(VueRouter);
const router = new VueRouter({
  mode: "history",
  base: process.env.BASE_URL,
  routes,
});

// router.beforeEach((to, from, next) => { //路由拦截
//   /*to 即将要进入的路由对象
//    *from 当前导航要离开的路由对象
//   */
//   // if(token){ //判断是否登录了
//     next('/')
//   // }else{
//   //   //没有 返回登录页
//   // }
// })

// router.afterEach(to => { 
//   window.scrollTo(0, 0)
//   // console.log('我触发了')
// })

// 解决连续点击跳转路由报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
    if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
    return originalPush.call(this, location).catch(err => err)
}

export default router;
